package com.paomi.client.activity.search;

import com.hannesdorfmann.mosby3.mvp.MvpBasePresenter;
import com.paomi.client.fragment.first.model.NewsJson;
import com.paomi.client.fragment.first.model.TicketJson;
import com.paomi.client.fragment.first.model.TicketListJson;
import com.paomi.client.net.Api;
import com.paomi.client.net.BaseCallback;
import com.paomi.client.net.Constants;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import retrofit2.Call;

/**
 * Created by pc on 2018/12/21
 * Describe:
 * com.paomi.client.activity.search
 */
public class SearchPresenter extends MvpBasePresenter<SearchMvpView> {
    private List<TicketJson> jsonList=new ArrayList<>();
    /**
     * 售票列表的数据请求
     * 参数名	是否必选	注释
     * content	true	搜索内容
     * pageNum	true	页码
     * pageSize false	每页展示数量(默认10)
     * sort	false	排序规则(默认0) 0 时间 1 热度
     */
    public void setTicketJsonList(int pageNum,String content) {
        Map<String, String> stringMap = new HashMap<>();
        stringMap.put("content", content);
        stringMap.put("pageNum", ""+pageNum);
        stringMap.put("pageSize", "" + Constants.PAGE_SIZE);
        stringMap.put("sort", "0");
        Api.getInstanceService(Constants.Ticket_URL).getSearchTicket(stringMap).enqueue(new BaseCallback<TicketListJson>() {
            @Override
            public void onResponse(Call<TicketListJson> call, TicketListJson result) {
                if(pageNum==1){
                    jsonList.clear();
                }
                jsonList.addAll(result.getReturnData().getData());
                getView().getTicketList(jsonList);
            }
        });
    }

    //获取资讯列表
    public void setInfoData(int pageNme, String content, String classify) {
        Map<String, String> stringMap = new HashMap<>();
        stringMap.put("content", content);
        stringMap.put("pageNum", "" + pageNme);
        stringMap.put("pageSize", "" + Constants.PAGE_SIZE);
        stringMap.put("sort", classify);//0是时间，1是热度
        Api.getInstanceService(Constants.Ticket_URL).getSearchNews(stringMap).enqueue(new BaseCallback<NewsJson>() {
            @Override
            public void onResponse(Call<NewsJson> call, NewsJson result) {
                if(result.getReturnData()!=null){
                    if(isViewAttached()){
                        getView().getInfoData(result.getReturnData().getData());
                    }
                }
            }
        });
    }
}
